﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DOAN.BLL;
using DOAN.Public;

namespace DOAN.GUI.Form
{
    public partial class frmThayDoiQuiDinh : DevExpress.XtraEditors.XtraForm
    {
        ThamSoBLL _thamSo;
        ThamSoPublic _p;

        public frmThayDoiQuiDinh()
        {
            InitializeComponent();
        }

        private void txtHanThanhToan_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!Char.IsDigit(e.KeyChar) && !Char.IsControl(e.KeyChar))
            {
                e.Handled = true;
                MessageBox.Show("Hạn Thanh Toán Chỉ Chứa Kí Tự Số", "KHÔNG HỢP LỆ");
            }
        }

        private void frmThayDoiQuiDinh_Load(object sender, EventArgs e)
        {
            _thamSo = new ThamSoBLL();
            DataTable dt = _thamSo.Load();
            txtHanThanhToan.Text = dt.Rows[0].ItemArray[0].ToString();
            txtNgayThanhToan.Text = dt.Rows[0].ItemArray[1].ToString();
            txtNgayGuiHoaDon.Text = dt.Rows[0].ItemArray[2].ToString();
            txtPhiDangKi.Text = String.Format("{0:0,0}", dt.Rows[0].ItemArray[3]);
        }

        private void btnCapNhat_Click(object sender, EventArgs e)
        {
            _p = new ThamSoPublic();
            _p.HanThanhToan = Int32.Parse("0" + txtHanThanhToan.Text);
            _p.NgayThanhToanHopDong = Int32.Parse(txtNgayThanhToan.Text);
            _p.NgayGuiHoaDon = Int32.Parse(txtNgayGuiHoaDon.Text);
            _p.PhiDangKi = Int32.Parse("0" + txtPhiDangKi.Text);
            _thamSo.Update(_p);
        }

        private void btnDong_Click(object sender, EventArgs e)
        {
            this.Close();
            this.Dispose();
        }
    }
}